package middle.ground.db;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * 数据库分页
 *
 * @param <T> 数据类型
 * @author jrl
 * @author jrl
 * @date 2020-12-01
 */
@Data
@NoArgsConstructor
public class Pagination<T> implements Serializable {

	private static final long serialVersionUID = -5789913418349925461L;

	public Pagination(int page, int limit) {
		this.page = page;
		this.limit = limit;
	}

	public Pagination(int page, int limit, List<T> data) {
		this.page = page;
		this.limit = limit;
		this.data = data;
		this.end = null == data || data.size() < limit;
	}

	public Pagination(int page, int limit, List<T> data, int total) {
		this.page = page;
		this.limit = limit;
		this.data = data;
		this.end = null == data || data.size() < limit;
	}

	/**
	 * 页码，从一开始
	 */
	private int page;
	/**
	 * 一页多少行
	 */
	private int limit;
	/**
	 * 分页查询之后的数据
	 */
	private List<T> data;
	/**
	 * 当前也是否是最后一页
	 */
	private boolean end;
	/**
	 * 总页数
	 */
	private Integer total;

	public void setData(List<T> data) {
		this.data = data;
		this.end = null == data || data.size() < limit;
	}
}
